package com.linjacy.httpproject.component;

import com.linjacy.httpproject.service.impl.UserServiceImpl;
import com.linjacy.httpproject.util.SpringUtil;
import com.mysql.cj.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@Component
public class ApplicationRunnerComponent implements ApplicationRunner {

    private static Logger logger = LoggerFactory.getLogger(ApplicationRunnerComponent.class);

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    QueueGenerationService queueGenerationService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        logger.info("系统启动");
        //queueGenerationService.init();
        //schedualWork();
        //UserServiceImpl userServiceImpl = SpringUtil.getBean("userServiceImpl", UserServiceImpl.class);
        //System.out.println(userServiceImpl);
    }

    public void schedualWork(){
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        //第一个参数:传递一个任务,Runnable或Callable对象;
        //第二个参数:添加定时任务后,再过多久开始执行定时任务;
        //第三个参数:定时任务执行的时间间隔;
        //第四个参数:时间单位,配合参数2和参数3一起使用;
        scheduledExecutorService.scheduleAtFixedRate(() -> {
            logger.info("定时执行");
        },5,5, TimeUnit.SECONDS);
    }
}
